package action.product;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Book;
import option.OperationEnum;
import service.BookService;

/**
 * 
 */
@SuppressWarnings("serial")
public class ProductServlet extends HttpServlet{
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String action = (String) request.getAttribute("action");
		if (action.equals(OperationEnum.PRODUCT_DETAIL.getValue())) {//跳转到某个产品详情页面
			Integer id = Integer.parseInt(request.getParameter("id"));
			BookService service = new BookService();
			Book book = null;
			try {
				book = service.queryBookById(id);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			request.setAttribute("book", book);
			request.setAttribute("user", request.getSession().getAttribute("user"));
			request.getRequestDispatcher("/WEB-INF/pages/main/product.jsp").forward(request, response);
		}
	}
}
